import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from "../views/Home.vue"
import { getCookie } from '@/utils/cookie';

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      title: 'Evo Surfers',
      isToken: false,
      keepAlive: false,
      showTop: true,
      showBottom: true
    },
  },
  {
    path: '/presale',
    name: 'Presale',
    // route level code-splitting
    // this generates a separate chunk (presale.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "presale" */ '../views/Presale.vue'),
    meta: {
      title: 'Presale',
      isToken: false,
      keepAlive: false,
      showTop: true,
      showBottom: true
    },
  },
  {
    path: '/recommend',
    name: 'Recommend',
    // route level code-splitting
    // this generates a separate chunk (recommend.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "recommend" */ '../views/Recommend.vue'),
    meta: {
      title: 'Recommend',
      isToken: false,
      keepAlive: false,
      showTop: true,
      showBottom: true
    },
  },
  {
    path: '/coming',
    name: 'Coming',
    // route level code-splitting
    // this generates a separate chunk (coming.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "coming" */ '../views/Coming.vue'),
    meta: {
      title: 'Coming Soon',
      isToken: false,
      keepAlive: false,
      showTop: true,
      showBottom: true
    },
  }
]

const router = new VueRouter({
  routes,
  scrollBehavior(to, from, saveTop) {
    if (saveTop) {
      return saveTop;
    } else {
      return { x: 0, y: 0 };
    }
  },
});

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next()
})
export default router
